package com.guet.mapper;

import com.github.pagehelper.Page;
import com.guet.DTO.PaperPageDTO;
import com.guet.Entity.*;
import com.guet.Entity.Options;
import com.guet.VO.PaperVO;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface TestMapper {


    void insertPaper(Paper paper);

    @Delete("delete from paper where id = #{id} and user_id = #{userId}")
    void deletePaperById(Long userId, Integer id);

    List<Questions> queryQuestionsByPaperId(Integer id);

    @Delete("delete from questions where paper_id = #{id}")
    void deleteQuestionsByPaperId(Integer id);

    @Delete("delete from options where questions_id = #{questionId}")
    void deleteOptionsByQuestionId(Integer questionId);

    @Delete("delete from correct_answers where questions_id = #{questionId}")
    void deleteCorrectAnswerByQuestionId(Integer questionId);

    // 分页查询试卷
    Page<PaperVO> list(PaperPageDTO paperPageDTO);

    void insertQuestion(Questions question);

    void insertOption(Options option);

    Integer queryOptionIdByLabelAndQuestionId(
            @Param("questionId") Integer questionId,
            @Param("label") String label
    );

    void insertCorrectAnswer(@Param("questionId") Integer id,
                             @Param("optionId") Integer correctOptionId);

    List<Options> queryOptionsByQuestionId(Integer id);

    String queryCorrectAnswerLabelByQuestionId(Integer id);

    String queryQuestionCorrectAnswer(Integer id);

    @Select("select * from paper where id = #{id}")
    PaperVO queryPageById(Integer id);

    void updateStatus(Integer id, Long userId, Integer status);

    void insertStuAnswerPaper(StuAnswerPaper stuAnswerPaper);

    void insertStuAnswerQuestion(StuAnswerQuestion stuAnswerQuestion);

    @Select("select * from stu_answer_paper where paper_id = #{paperId} and user_id = #{userId}")
    StuAnswerPaper queryStuAnswerPaperById(Integer paperId, Long userId);

    @Delete("delete from stu_answer_paper where id = #{id}")
    void deleteStuAnswerPaper(Integer id);

    @Delete("delete from stu_answer_question where stu_answer_paper_id = #{id}")
    void deleteStuAnswerQuestion(Integer id);

    void batchInsertStuAnswerQuestions(List<StuAnswerQuestion> questions);

    List<Map<String, Object>> queryAnswerById(@Param("paperId") Integer paperId, @Param("userId") Long userId);

    @Select("select * from paper where status = 1")
    List<Paper> queryAllPapers(Integer status);

    @Update("update paper set status = 3 where id = #{id}")
    void updateOverTimePaper(Integer id);

    String queryUserAnswer(Integer paperId, Long userId, Integer questionId);

    void insertStuScore(Score build);


    List<Integer> notTestUserIds(Integer id);

    void insertBatchStuScores(List<Score> collect);
}
